// // import ChengYu_GameFunctions from "../Common/ChengYu_GameFunctions";
// // import { ChengYu_GameData } from "../Data/ChengYu_GameData";
// // import { ChengYu_GameStorage } from "../Data/ChengYu_GameStorage";
// // import ChengYu_GamePanel from "../UI/ChengYu_GamePanel";
// // import ChengYu_GamePanel_1 from "../UI/ChengYu_GamePanel_1";
// // // import ChengYu_GamePanel_2 from "../UI/ChengYu_GamePanel_2";
// // // import ChengYu_GamePanel_3 from "../UI/ChengYu_GamePanel_3";
// // import ChengYu_WinPanel from "../UI/ChengYu_WinPanel";

import { _decorator, Component, director } from 'cc';
const { ccclass, property, executionOrder } = _decorator;

import UI from "../../../../../../../Script/Manager/UI";
import ChengYu_GameFunctions from "../Common/ChengYu_GameFunctions";
import { ChengYu_GameData } from "../Data/ChengYu_GameData";
import { ChengYu_GameStorage } from "../Data/ChengYu_GameStorage";
import ChengYu_GamePanel from "../UI/ChengYu_GamePanel";
import ChengYu_GamePanel_1 from "../UI/ChengYu_GamePanel_1";
import ChengYu_WinPanel from '../UI/ChengYu_WinPanel';
// import ChengYuJieLong_WinPanel from '../UI/ChengYuJieLong_WinPanel';
// import ChengYu_WinPanel from "../UI/ChengYu_WinPanel";
// // 慢一点执行

@ccclass('ChengYu_Main')
@executionOrder(101)
export default class ChengYu_Main extends Component {
        static Instance: ChengYu_Main;
        onLoad() {
                console.log(`ChengYu_Main-onLoad====>`);

                ChengYu_Main.Instance = this;

                // XXL_GameEventManager.AddListener();

                console.log(`ChengYu_Main.onLoad`);

                this.Init();
        }
        async Init() {
                ChengYu_GameStorage.initData();

                ChengYu_GameData.InitData();

                let level = ChengYu_GameData.Get_CurrentLevelIndex();// UserManger.getInstance().getUserInfo().getCurLevel() + 1;
                // console.log(`level---`, level);

                // const data = await ChengYu_GameFunctions.GetChengYuLevelData(level);
                // console.log(`data---`, data);
                // const data = {
                //     levelType: 1
                // }
                // ChengYu_GameData.GameData.LevelData = await ChengYu_GameFunctions.GetLevelItemAll(level);
                ChengYu_GameData.GameData.LevelData = await ChengYu_GameFunctions.GetLevelItemGame_1(level);
                // console.log(`XXL_GameData.GameData.LevelData---`, ChengYu_GameData.GameData.LevelData);

                // let main_questions = await bdlMgr.getRes<JsonAsset>(`hall`, `config/json/chengyu/main_questions`, JsonAsset)
                // console.log(`main_questions`, main_questions);
                // XXL_GameData.GameData.LevelData = main_questions.json[level];

                // ChengYu_GameData.GameData.levelType = data.levelType;

                // console.log(`data.levelType---`, data.levelType);

                // if (data.levelType === 1) {
                ChengYu_GamePanel_1.Instance.ShowOn();
                // } else if (data.levelType === 2) {
                //     ChengYu_GamePanel_2.Instance.ShowOn();
                // } else if (data.levelType === 3) {
                //     ChengYu_GamePanel_3.Instance.ShowOn();
                // }

                ChengYu_GamePanel.Instance.ShowOn();
                ChengYu_GamePanel.Instance.Refresh();
        }
        async GameWin() {
                // if (XXL_GameData.IsGameWin === true) {
                //     return;
                // }

                // XXL_GameData.IsGameWin = true;

                // console.log(`结束`);

                ChengYu_GamePanel.Instance.unschedule(ChengYu_GamePanel.Instance.TimerCallback);

                let chengyuList;

                // let level = ChengYu_GameData.CurLevel + 1; // UserManger.getInstance().getUserInfo().getCurLevel() + 1;
                // const data = await ChengYu_GameFunctions.GetChengYuLevelData(level);
                // const data = {
                //     levelType: 1
                // }
                // console.log(`data---`, data);

                // if (data.levelType === 1) {
                chengyuList = ChengYu_GameData.GameData.LevelData.idiom; // 数组
                // } else if (data.levelType === 2) {
                //         chengyuList = [ChengYu_GameData.GameData.LevelData.idiom]; // 字符串
                // } else if (data.levelType === 3) {
                //         chengyuList = [ChengYu_GameData.GameData.LevelData.word]; // word
                // }

                // ChengYu_WinPanel.Instance.ShowOn(chengyuList);

                UI.Instance.CreatePanel_sub(`ChengYu_Prefab`, `ChengYu_WinPanel`, ChengYu_WinPanel, chengyuList);


                // gameFunc.showPanel(GameResConst.PREFABS_PATH.XXL_WinPanel, chengyuList);

                // UserManger.getInstance()
                //     .getUserInfo()
                //     .setCurLevel(UserManger.getInstance().getUserInfo().getCurLevel() + 1);
        }
        上一关() {
                ChengYu_GameStorage.data.current_level--;
                ChengYu_GameStorage.saveData();
                director.loadScene(ChengYu_GameData.SCENE_NAME.game);
        }
        下一关() {
                ChengYu_GameStorage.data.current_level++;
                ChengYu_GameStorage.saveData();
                director.loadScene(ChengYu_GameData.SCENE_NAME.game);
        }
        Replay() {
                director.loadScene(ChengYu_GameData.SCENE_NAME.game);
                // SceneManager.getInstance().loadSceneWithBundle(BundleType.Game, SceneConst.SCENE_NAME.xxlGame, { forceLoadScene: true });
        }
}

// /** 调试 */
window["ChengYu_Main"] = ChengYu_Main;